home *** CD-ROM | disk | FTP | other *** search
- // Copyright (C) 1997-2002 Alias|Wavefront,
- // a division of Silicon Graphics Limited.
- //
- // The information in this file is provided for the exclusive use of the
- // licensees of Alias|Wavefront. Such users have the right to use, modify,
- // and incorporate this code into other products for purposes authorized
- // by the Alias|Wavefront license agreement, without fee.
- //
- // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
- // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
- // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
- // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
- // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
- // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
- // PERFORMANCE OF THIS SOFTWARE.
- //
- //
- // Alias|Wavefront Script File
- // MODIFY THIS AT YOUR OWN RISK
- //
- // Creation Date: Dec 15, 1999
- //
- // Author: hmw
- //
- // Description:
- // Arguments are passed in $args[] array. We'll call
- // the first arg ($args[0]) $levelString. The second
- // argument $args[1], if present, will set the
- // displayFilter.
- //
- // Set the subdiv diplay level on the active
- // objects according to $levelString. If $levelString
- // contains a "+" or "-" the value of level is
- // taken to be relative, otherwise it's
- // absolute. Returns 1 if setting the level
- // succeeded, and 0 if not. Probable causes
- // of failure include: poorly fomed $levelString
- // argument (+/- must be the first character of
- // $levelString), attempting to set the
- // display level to a level that doesn't exist, or
- // no valid subdiv surface selected.
- //
- // Examples
- // // Decrease current level by two.
- // //
- // setSubdivDisplayLevel "-2";
- //
- // // Set the current display level to three.
- // //
- // setSubdivDisplayLevel 3;
- //
- // // Increase current level by one.
- // //
- // setSubdivDisplayLevel "+1";
- //
- global proc int setSubdivDisplayLevelAndFilter( string $targets[],
- string $levelString,
- int $filter )
- {
- int $foundValidTarget = false;
- int $setValidValue = false;
-
- string $target;
-
- int $isPlus = false;
- int $isMinus = false;
- int $level = 0;
-
- // Find out whether the level passed in represents
- // an absolute or a relative change.
- //
- string $relativeString = substring( $levelString, 1, 1 );
- if( $relativeString == "+" ) {
- $isPlus = true;
- $level = substring( $levelString, 2, size( $levelString ) );
- }
- else if( $relativeString == "-" ) {
- $isMinus = true;
- $level = substring( $levelString, 2, size( $levelString ) );
- }
- else {
- $level = $levelString;
- }
-
- // First process
- //
- string $cmd;
- string $errorMessage = "";
-
- for( $target in $targets ) {
- string $attrs[] = `listAttr ($target+".displayLevel") ($target+".displayFilter")`;
- int $isSubdiv = size( $attrs ) == 2;
- if( $isSubdiv == 1 ) {
- $foundValidTarget = true;
-
- int $currLevel = `getAttr ($target + ".displayLevel")`;
- int $newLevel = $level;
-
- if( $isPlus ) {
- $newLevel = $currLevel + $level;
- }
- else if( $isMinus ) {
- $newLevel = $currLevel - $level;
- }
-
- int $deepest = `subdiv -query -deepestLevel $target`;
-
- // It's not an error at this point if we try setting above
- // the maximum or below the minimum, but we will cause an
- // an error condition later if NONE of our targets succeeded.
- // In that case, set the error message to be something
- // useful, even though it won't contain info about all the
- // targets that caused it to fail.
- //
- if(( $newLevel <= $deepest )
- && ( $newLevel >= 0 ))
- {
- $setValidValue = true;
- // Set the display level
- //
- $cmd = ( "setAttr \"" + $target + ".displayLevel\" " +
- $newLevel + "; " );
-
- // Set the display filter
- //
- $cmd += ( "setAttr \"" + $target + ".displayFilter\" " +
- $filter + "; " );
-
- catch( `evalEcho $cmd` );
- } else if( $newLevel > $deepest ) {
- $errorMessage = ("Cannot display finer than level "+$deepest + ".");
- } else if( $newLevel < 0 ) {
- $errorMessage = ("Cannot display coarser than level 0.");
- }
- }
- }
-
- // No valid targets on active list.
- //
- if( $foundValidTarget == 0 ) {
- error( "No valid subdivision surface or subdivision component selected." );
- }
- // None of our targets worked.
- //
- else if( $setValidValue == 0 ) {
- error( $errorMessage );
- }
-
- return $setValidValue;
- }
-